import React from 'react';
import {Button, Tooltip} from 'antd';
import {DiffOutlined, EditOutlined} from '@ant-design/icons';
import {ButtonType} from "antd/es/button";
import {Access} from "umi";
import {FormAction} from "@/types/global"; // 假设 Access 组件在 @/components/Access

export interface AccessDeleteBtnProps {
  accessKey: boolean; // 权限检查的键值
  action?: FormAction
  tooltipTitle?: string; // 工具提示的标题
  onSubmit: () => Promise<any>; // 删除操作的函数
  buttonType?: ButtonType; // 按钮类型
  icon?: React.ReactNode | boolean; // 自定义按钮图标
  disabled?: boolean;
  children?: React.ReactElement; // 自定义 children
}

const AccessUpdateBtn: React.FC<AccessDeleteBtnProps> = ({
                                                           accessKey,
                                                           tooltipTitle = '删除该条记录',
                                                           disabled = false,
                                                           buttonType,
                                                           icon,
                                                           children,
                                                           onSubmit,
                                                           action
                                                         }) => {
  return (
    <Access accessible={accessKey}>
      <Tooltip title={tooltipTitle}>
        {children ? children : (
          <Button
            onClick={onSubmit}
            disabled={disabled}
            type={buttonType}
            icon={icon === false ? undefined : icon ? icon : action === 'add' ? <DiffOutlined/> : <EditOutlined/>}
          />
        )}
      </Tooltip>
    </Access>
  );
};

export default AccessUpdateBtn;
